package com.simon.app.october.modules.job.service.impl;

import com.simon.app.october.common.utils.PageUtil;
import com.simon.app.october.common.utils.QueryPage;
import com.simon.app.october.modules.job.dao.ScheduleJobLogDao;
import com.simon.app.october.modules.job.entity.ScheduleJobLogEntity;
import com.simon.app.october.modules.job.service.ScheduleJobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("scheduleJobLogService")
public class ScheduleJobLogServiceImpl implements ScheduleJobLogService {
    @Autowired
    private ScheduleJobLogDao scheduleJobLogDao;
    @Override
    public PageUtil<ScheduleJobLogEntity> getListPage(QueryPage params) {
        int total = scheduleJobLogDao.getTotalByParams(params);
        int limit = params.getLimit();
        int pageNum = (int) Math.ceil(total/(double)limit);

        PageUtil<ScheduleJobLogEntity> page = new PageUtil<>();
        page.setTotalCount(total);
        page.setCurrPage(params.getPage());
        page.setPageSize(limit);
        page.setList(scheduleJobLogDao.getPageByParams(params));
        page.setTotalPage(pageNum);

        return page;
    }

    @Override
    public void save(ScheduleJobLogEntity entity) {
        scheduleJobLogDao.insert(entity);
    }
}
